<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="__ROOT__/static/admin/css/images.css">
    <link rel="stylesheet" href="__ROOT__/static/plugins/bootstrap/css/bootstrap.min.css">
    <script type="text/javascript" src="__ROOT__/static/plugins/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="__ROOT__/static/plugins/layer/layer.min.js"></script>
</head>
<body>
    <div class="outer">
        <div class="title">
            <div class="title_msg"><strong><small class="glyphicon glyphicon-th"></small>&nbsp;轮播图列表</strong></div>
            <div class="title_op">
            <p id="toadd">
                <span class="glyphicon glyphicon-plus"></span> 添加
            </p>
                <p id="homeSet">
                    <span class="glyphicon glyphicon-pencil	"></span>首页设置
                </p>
                <p id="goodsSet">
                    <span class="glyphicon glyphicon-pencil	"></span>商城设置
                </p>
                <span>&emsp;&emsp;&emsp;禁止轮播有bug 全部禁止了轮播就一个都看不到了！解决它！</span>
            </div>
        </div>
        <div class="inner">
            <ul class="inner_show">
                {volist name="imgs" id="vo"}
                <li>
                    <p><img style="width: 200px;height:150px;" src="__ROOT__/{$vo.imgs_url}" alt=""/></p>
                    <p>
                        {if condition="($vo.status nheq 1) AND ($vo.status nheq 0)"}
                        <p><sup class="prompt_info_goods">商城轮播图</sup></p>
                        <span class="set_home" onclick="setHome('{$vo.id}')">设为首页</span>
                        <span class="cancel" onclick="remove('{$vo.id}')">取消轮播</span>
                        {elseif condition="($vo.status nheq 2) AND ($vo.status nheq 0)"/}
                        <p><sup class="prompt_info_home">首页轮播图</sup></p>
                        <span class="set_goods" onclick="goodsSet('{$vo.id}')">设为商城</span>
                        <span class="cancel" onclick="remove('{$vo.id}')">取消轮播</span>
                        {else /}
                        <p><sup class="prompt_info_not">还未设置</sup></p>
                        <span class="set_home" onclick="setHome('{$vo.id}')">设为首页</span>
                        <span class="set_goods" onclick="goodsSet('{$vo.id}')">设为商城</span>
                        {/if}
                        <span id="delete" onclick="del('{$vo.id}')">删除图片</span>
                    </p>
                </li>

                {/volist}
            </ul>
            <div style="clear: both;"></div>
            <div class="page">{$page}</div>
        </div>
    </div>
</body>
<script>

    //增加按钮
    $(function(){
        $("#toadd").bind('click',function(){
            layer.open({
                type: 2,
                area: ['700px', '450px'],
                fixed: true, //不固定
                maxmin: true,
                title:'上传图片',
                content: "{:url('admin/Images/getReturnImg')}"
            });
        });
        //顶部首页设置按钮
        $("#homeSet").bind('click',function(){
            var index=layer.open({
                title:'首页轮播图的个数（最小3个/最多5个）',
                area:['auto','200px'],
                content:'<select id="select_id">' +
                '<option value="3">轮播3个</option>'+
                '<option value="4">轮播4个</option>'+
                '<option value="5">轮播5个</option>'+
                '</select>',
                yes: function(index,msg){
                    var Rmsg ={};
                    Rmsg.limit = $('#select_id').val();
                    $.post("{:url('home/Images/getNum')}",Rmsg,function(data){
                        if(data>0){
                            layer.msg('修改成功');
                            setTimeout('window.parent.location.href="{:url(\'home/Index/index\')}"',2500);
                        }else{
                            layer.msg('当前轮播个数未改变');
                        }
                    });
                    layer.close(index);
                }
            })
        });

        //顶部商城设置按钮
        $("#goodsSet").bind('click',function(){
            var index=layer.open({
                title:'商城轮播图的个数（最小3个/最多5个）',
                area:['auto','200px'],
                content:'<select id="select_id">' +
                '<option value="3">轮播3个</option>'+
                '<option value="4">轮播4个</option>'+
                '<option value="5">轮播5个</option>'+
                '</select>',
                yes: function(index,msg){
                    var Rmsg ={};
                    Rmsg.limit = $('#select_id').val();
                    $.post("{:url('home/Shopping/getNum')}",Rmsg,function(data){
                        if(data>0){
                            layer.msg('修改成功');
                            setTimeout('window.parent.location.href="{:url(\'home/Index/index\')}"',2500);
                        }else{
                            layer.msg('当前轮播个数未改变');
                        }
                    });
                    layer.close(index);
                }
            })
        })

    });



    //删除按钮
    function del(id) {
        var del={};
        del.id=id;
        layer.confirm('是否删除图片？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.post("{:url('admin/Images/delImages')}",del,function(data){
//                console.dir(data);
                if(data>0){
                    layer.msg('删除成功', {icon: 6});
                    setTimeout('location.href="{:url(\'admin/Images/index\')}"',2500);
                }
            });
        })
    }

    //设置为首页
    function setHome(id){
        var setHome={};
        setHome.id=id;
        layer.confirm('是否设置为首页？', {
            btn: ['是','否'] //按钮
        }, function(){
            $.post("{:url('admin/Images/setHomeImages')}",setHome,function(data){
                console.dir(data);
                if(data>0){
                    layer.msg('设置成功');
                    setTimeout('location.href="{:url(\'admin/Images/index\')}"',2500);
                }
            });
        })
    }

    //设置为商城
    function goodsSet(id){
        var goodsSet={};
        goodsSet.id=id;
        layer.confirm('是否设置为商城？', {
            btn: ['是','否'] //按钮
        }, function(){
            $.post("{:url('admin/Images/setGoodsImages')}",goodsSet,function(data){
                console.dir(data);
                if(data>0){
                    layer.msg('设置成功');
                    setTimeout('location.href="{:url(\'admin/Images/index\')}"',2500);
                }
            });
        })
    }
    //取消设置
    function remove(id){
        var remove={};
        remove.id=id;
        layer.confirm('是否取消轮播？', {
            btn: ['是','否'] //按钮
        }, function(){
            $.post("{:url('admin/Images/removeSet')}",remove,function(data){
                console.dir(data);
                if(data>0){
                    layer.msg('设置成功');
                    setTimeout('location.href="{:url(\'admin/Images/index\')}"',2500);
                }
            });
        })
    }
</script>
</html>